package com.ibm.check;

import java.io.File;
import java.io.IOException;

import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;

import org.xml.sax.SAXException;

public class CheckXML {

	private static String xml = "sample/workflow_sample_czy.xml";
	
	private static String xsd = "xsd/workflow_v1.xsd";

//	private static String test = "xml/migration_V2R1/test/PostProcessed.xml";
//	private static String test = "html/Migration_R13h/PostProcessed.xml";
//	E:/WorkSpace/Eclipse/IBM_Workflow_Process/html/Migration_R13h.htm
	private static String test="E:/WorkSpace/Eclipse/IBM_Workflow/html/Migration_V2R1/PostProcessed.xml";
	/**
	 * @param args
	 * @throws IOException

	 */
	public static void main(String[] args) throws SAXException, IOException {

        // 建立 schema 工厂

        SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");

        // 建立验证文档文件对象，利用此文件对象所封装的文件进行 schema 验证

        File schemaFile = new File(xsd);

        // 利用 schema 工厂，接收验证文档文件对象生成 Schema 对象

        Schema schema = schemaFactory.newSchema(schemaFile);

        // 通过 Schema 产生针对于此 Schema 的验证器，利用 xsd 进行验证

        Validator validator = schema.newValidator();

        // 得到验证的数据源，就是 xml

        Source source = new StreamSource(test);

        // 开始验证，成功输出 success!!! ，失败输出 fail

        try {

            validator.validate(source);

            System.out.println("success!!!");

        } catch (Exception ex) {
        	ex.printStackTrace();
            System.out.println(ex.getMessage());

        }
	}
}
